package com.yonghui.sandbox.service.impl;

import com.yonghui.sandbox.dto.LoginParamDTO;
import com.yonghui.sandbox.dto.LoginResultDTO;
import com.yonghui.sandbox.service.LoginService;
import com.yonghui.sandbox.service.LoginUserService;
import com.yonghui.sandbox.vo.LoginParamVO;
import com.yonghui.sandbox.vo.LoginResultVO;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Random;

/**
 * @description: TODO
 * @author: zhangtong
 * @create: 2021-03-15 13:43
 **/
@Service
public class LoginUserServiceImpl implements LoginUserService {

    @DubboReference(version = "${sandbox.service.version}")
    private LoginService loginService;

    @Override
    public LoginResultVO getLoginUserInfo(LoginParamVO loginParamVO) {
        LoginParamDTO loginParamDTO = new LoginParamDTO();
        BeanUtils.copyProperties(loginParamVO, loginParamDTO);
        LoginResultDTO loginInfo = loginService.getLoginInfo(loginParamDTO);
        LoginResultVO loginResultVO = new LoginResultVO();
        BeanUtils.copyProperties(loginInfo, loginResultVO);
        return loginResultVO;
    }

    @Override
    public LoginResultVO getThirdLoginInfo(LoginParamVO loginParamVO) {
        LoginResultVO loginResultVO = new LoginResultVO();
        loginResultVO.setName(loginParamVO.getName());
        loginResultVO.setPwd(loginParamVO.getPwd());
        loginResultVO.setId(1000);
        loginResultVO.setNickname("测试"+loginParamVO.getName());
        Random random = new Random();
        int rNumber = random.nextInt(10000);
        loginResultVO.setPhone("1590089"+rNumber);
        loginResultVO.setSex(1);
        loginResultVO.setBirthday(new Date());
        return loginResultVO;
    }


}
